﻿@{
    ViewBag.Title = "登录";
    Layout = "~/Views/Shared/_iframe.cshtml";
}
<header class="am-topbar admin-header">
    <div class="am-topbar-brand">
        <strong>新</strong> <small>管理后台</small>
    </div>

    <button class="am-topbar-btn am-topbar-toggle am-btn am-btn-sm am-btn-success am-show-sm-only" data-am-collapse="{target: '#topbar-collapse'}"><span class="am-sr-only">导航切换</span> <span class="am-icon-bars"></span></button>

    <div class="am-collapse am-topbar-collapse" id="topbar-collapse">

        <ul class="am-nav am-nav-pills am-topbar-nav am-topbar-right admin-header-list">
            <li>
                <a href="javascript:;">
                </a>
            </li>
        </ul>
    </div>
</header>
@if (MvcApplication.Common.UserSession.User == null)
{
    <section class="am-panel am-panel-default" style="width: 1000px; margin: 20px auto 0 auto;">
        <header class="am-panel-hd">
            <h3 class="am-panel-title">后台登录</h3>
        </header>
        <div class="am-panel-bd">
            <form class="am-form am-form-horizontal" id="form">
                <div class="am-form-group am-form-group-sm">
                    <label class="am-u-sm-5 am-form-label"></label>
                </div>
                <div class="am-form-group am-form-group-sm">
                    <label for="email" class="am-u-sm-4 am-form-label">邮箱：</label>
                    <div class="am-u-sm-8">
                        <input id="email" type="email" class="am-form-field" style="width: 300px" name="email" placeholder="请输入邮箱号">
                    </div>
                </div>
                <div class="am-form-group am-form-group-sm">
                    <label for="psw" class="am-u-sm-4 am-form-label">密码：</label>
                    <div class="am-u-sm-8">
                        <input id="psw" type="password" class="am-form-field" style="width: 300px" name="psw" minlength="6" placeholder="请输入密码">
                    </div>
                </div>
                <div class="am-form-group">
                    <div class="am-u-sm-2 am-u-sm-offset-4">
                        <button type="button" class="am-btn am-btn-primary am-btn-block" onclick="login();" id="loginEl">登入</button>
                    </div>
                </div>
                <input type="hidden" id="redirect" value="@Request.QueryString["ReturnUrl"]" />
            </form>
        </div>
    </section>

    @section scripts{
        <script>
            function login() {
                $("#form").submit();
            }
            $("#form").validate({
                highlight: function (element) {
                    $(element).closest('.am-form-group').addClass('am-form-error');
                },

                success: function (label) {
                    label.closest('.am-form-group').removeClass('am-form-error');
                    label.remove();
                },
                submitHandler: function (form) {
                    //$(form).submit();
                    layer.msg('登录中...', { icon: 16 });
                    $.post('checklogin', $("#form").serializeArray()).success(function (res) {
                        if (res.success) {
                            var direct = $('#redirect').val();
                            if (!direct) {
                                location.href = "/manager";
                                return;
                            }
                            location.href = direct;
                        } else {
                            layer.msg("用户名或密码不正确", { icon: 2 });
                        }
                    }).error(function () {
                        layer.msg("服务器异常", { icon: 2 });
                    });
                },
                rules: {
                    email: {
                        required: true,
                        email: true,
                    },
                    psw: {
                        required: true,
                        minlength: 6,
                    }
                },
                messages: {
                    firstname: "请输入姓名",
                    email: {
                        required: "请输入Email地址",
                        email: "请输入正确的email地址"
                    },
                    psw: {
                        required: "请输入密码",
                        minlength: "密码不能小于6个字 符"
                    }
                }
            });

            $('#psw').keydown(function (event) {
                if (event.keyCode === 13) login();
            })
            $('#email').focus();
        </script>
    }
}
else
{
    <h4>无权访问</h4>
}
